<template>
  <div class="flex-head">
    <div class="flex-left">
      
    <div class="sidebar-logo-container" :class="{ collapse: isCollapse }">
      <transition name="sidebarLogoFade">
        <router-link key="collapse" class="sidebar-logo-link" to="/">
          <img :src="require('@/assets/logo.png')" class="sidebar-logo" />
          <h1 v-if="!isCollapse" class="sidebar-title" style="color: #eee">
            北京清创智环科技有限公司门户网站后台管理系统
          </h1>
        </router-link>
      </transition>
    </div>
      <span @click="changeCollapse">
        <span v-if="!isCollapse">
          <i class="iconfont icon-shouqicaidan" />
        </span>
        <span v-else>
          <i class="iconfont icon-zhankaicaidan" />
        </span>
      </span>
      <Breadcrumb />
    </div>
    <div class="flex-right">
      <div style="display: inline-block; margin-right: 20px;" >
        <span class="iconfont icon-guanwang_" style="font-size: 18px; font-weight: 500; cursor: pointer;" @click="gotoWS"></span>
      </div>
      <div style="display: inline-block; cursor: pointer;">
        <el-dropdown style="height: 48px"
                     @command="handleCommand"
                     :hide-on-click="false">
          <div class="user-info">
            <div class="user-name">{{ userStore.userInfo.name }}</div>
            <el-avatar shape="circle"
                       size="small"
                       fit="none"
                       src="">
            </el-avatar>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <!-- <el-dropdown-item command="userInfo">
                <div>个人信息</div>
              </el-dropdown-item> -->
              <el-dropdown-item command="logout">
                <div>退出登录</div>
              </el-dropdown-item>
              <div class="down-line"></div>

            </el-dropdown-menu>
          </template>
        </el-dropdown>

      </div>

    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, onMounted, toRefs } from "vue";
import Breadcrumb from "@/components/Breadcrumb/index.vue";
import { useRouter } from "vue-router";
import { useUserStore } from "@/stores/user";
export default defineComponent({
  name: "appHeader",
  props: {
    isCollapse: Boolean
  },
  components: {
    Breadcrumb
  },
  emits: ["changeCollapse"],
  setup(props, context) {
    const userStore = useUserStore();
    const router = useRouter();
    const state = reactive({
      name: "系统名称",
      userAvatar: "",
      username: ""
    });
    onMounted(() => {
      state.username = userStore.userInfo.name;
    });
    const changeCollapse = () => {
      context.emit("changeCollapse", !props.isCollapse);
    };
    const handleCommand = (e: string | number | object) => {
      if (e == "logout") {
        userStore.logoutAct();
        
      } else if (e == "userInfo") {
        console.log("userInfo");
      }
    };
    const gotoWS = () => {
      window.open(`http://home.ibemlab.com/`);
    }
    return {
      ...toRefs(state),
      changeCollapse,
      handleCommand,
      userStore,
      gotoWS,
    };
  }
});
</script>
<style scoped lang="scss">
.flex-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .flex-left {
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
  .user-info {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .user-name {
      margin-right: 10px;
    }
  }
}
.flex-right {
  display: flex;
  align-items: center;
}
.iconfont {
  font-size: 24px;
  margin-right: 10px;
  line-height: 30px;
}
.sidebar-logo-container {
  position: relative;
  width: 100%;
  height: 50px;
  line-height: 50px;
  text-align: center;
  overflow: hidden;

  & .sidebar-logo-link {
    transition: 0.1s;
    height: 100%;
    width: 100%;

    & .sidebar-logo {
      width: auto;
      height: 25px;
      vertical-align: middle;
      margin-right: 12px;
    }

    & .sidebar-title {
      display: inline-block;
      margin: 0;
      color: #000000 !important;
      font-weight: 700;
      line-height: 50px;
      font-size: 16px;
      font-family: Avenir, Helvetica Neue, Arial, Helvetica, sans-serif;
      vertical-align: middle;
    }
  }

  &.collapse {
    .sidebar-logo {
      margin-right: 0px;
    }
  }
}
</style>
